<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding: 0;
        }
        .content{
            height: 2000px;
        }
        .goTop{
            width: 100px;
            height: 100px;
            background-color: #bbb;
            text-align: center;
            line-height: 100px;
            position:fixed;
            bottom:100px;
            right: 20px;
            display: block;
        }
    </style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>	
</head>
<body>
    <div class="content">
        <h2>返回首屏</h2>
        <div class="goTop">返回</div>
    </div>

    <script>
		
		$('div.goTop').click( function() {
			$(document).scrollTop(0);
		});
		
		
		$(window).scroll( function() { 
			let scrollValue = $(document).scrollTop();
			if(scrollValue >= 400){
				$('.goTop').css('display', 'block');
			} else {
				$('.goTop').css('display', 'none');
			}
		} );
		
    </script>
</body>
</html>